
package com.scalar.chiptrack.operations.dataentry.actions;


import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.scalar.chiptrack.ChipTrackAction;
import com.scalar.chiptrack.operations.dataentry.dao.SortDataEntryDAO;
import com.scalar.chiptrack.operations.dataentry.forms.SortDataEntryForm;
import com.scalar.chiptrack.operations.process.dao.SortProcessDAO;




public final class SortBinDataEntryAction extends ChipTrackAction {

    public SortBinDataEntryAction() {
    }

public ActionForward execute (ActionMapping mapping, 
                                  ActionForm form, 
                                  HttpServletRequest request, 
                                  HttpServletResponse response) throws Exception {


		 HttpSession ses = request.getSession();

		SortDataEntryForm sortDataEntryForm = (SortDataEntryForm) form;

		ses.setAttribute("sortdataentryform",sortDataEntryForm);
		

		String processStepId=sortDataEntryForm.getProcessStepId();
		String lotId		= sortDataEntryForm.getLotId();

		String noOfBins=SortProcessDAO.getAllSortBins(Integer.parseInt(processStepId));
		SortDataEntryDAO sortDataEntryDao = new SortDataEntryDAO();
		
	


		String action = request.getParameter("action");

		if(action==null)
	    action = "";
		
		

		int count = Integer.parseInt(request.getParameter("wafer"));
		
		request.setAttribute("waferNo",(String)request.getParameter("wafer"));

		String waferNumber = "Wafer"+count;
		count = count-1;

		String [] waferId		= sortDataEntryForm.getWaferId();
		String [] remark		= sortDataEntryForm.getRemark();
		//String [] waferYield	= sortDataEntryForm.getWaferYield();
		//String [] pass			= sortDataEntryForm.getPass();
		//String [] total			= sortDataEntryForm.getTotal();

		//System.out.println("lotId "+lotId);
		//System.out.println("noOfBins "+noOfBins);


		sortDataEntryDao.saveWafer(Integer.parseInt(lotId),waferId[count],waferNumber,remark[count],Integer.parseInt(noOfBins)); 

		ArrayList binQuantityList=(ArrayList)sortDataEntryDao.getBinQty(Integer.parseInt(lotId),waferNumber);

		request.setAttribute("binQuantityList",binQuantityList);
		ses.setAttribute("binQuantityList",binQuantityList);
		request.setAttribute("binList",binQuantityList);
		request.setAttribute("waferId",waferId[count]);
		request.setAttribute("dieWafer",sortDataEntryForm.getDieWafer());
			
		return (mapping.findForward("success")); 
	}
	
}